package pers.gxm.prototype;

public class MessageBox implements Product{
    public static void main(String[] args) {
        MessageBox messageBox = new MessageBox('*');
        Product p;
        try {
           p = messageBox.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        p.use("Hello,World");

    }

    private char decochar;
    public MessageBox(char decochar){
        this.decochar = decochar;
    }

    private MessageBox(MessageBox messageBox){
        this.decochar = messageBox.decochar;
    }
    @Override
    public void use(String str) {
        byte[] bytes = str.getBytes();
        int length = bytes.length;
        for(int i = 0;i < length + 4; i++){
            System.out.print(decochar);
        }
        System.out.printf("\n%c %s %c\n",decochar,str,decochar);
        for(int i = 0;i < length + 4; i++){
            System.out.print(decochar);
        }
    }

    @Override
    protected Product clone() throws CloneNotSupportedException {
        return new MessageBox(this);
    }
}
